package com.lagou.edu.service;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletResponse;

/**
 * User 服务模块的 Feign 远程调用接口声明
 */
@Primary
@FeignClient(
        value = "lagou-service-user",
        fallback = UserServiceFeign.UserServiceFallbackImpl.class
)
public interface UserServiceFeign {
    /**
     * 是否已注册，根据邮箱判断,true代表已经注册过， false代表尚未注册
     * @param email
     * @return true/false
     */
    @RequestMapping("/api/user/isRegistered/{email}")
    public boolean isRegistered(@PathVariable("email")String email);

    /**
     *
     * @param token
     * @return 邮箱地址
     */
    @RequestMapping("/api/user/info/{token}")
    public String info(@PathVariable("token")String token);

    /**
     * 加载用户账号的 token
     * @param email
     * @return
     */
    @RequestMapping("/api/user/loadToken/{email}")
    String loadToken(@PathVariable("email")String email);

    @Component
    class UserServiceFallbackImpl implements UserServiceFeign {
        @Override
        public boolean isRegistered(String email) {
            return false;
        }

        @Override
        public String info(String token) {
            return null;
        }

        @Override
        public String loadToken(String email) {
            return null;
        }
    }
}
